package com.aj.http.response;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.annotation.SuppressLint;

import com.aj.databases.entry.BabyPrayLetterInfo;
import com.aj.databases.entry.PrayLetterInfo;

@SuppressLint("NewApi")
public class BabyPrayLetterResponse extends BaseRespond {

	private BabyPrayLetterInfo babyPrayLetterInfo;

	public BabyPrayLetterResponse(JSONObject json) {
		super(json);
		if (common != null && common.getResult() != null) {
			try {
				if (common.getResult() == null) {
					return;
				}
				babyPrayLetterInfo = new BabyPrayLetterInfo();
				JSONObject jsonObject = common.getResult();
				babyPrayLetterInfo.setBabyId(jsonObject.getString("babyId"));
				if (!jsonObject.isNull("babyCallName")) {
					babyPrayLetterInfo.setBabyCallName(jsonObject
							.getString("babyCallName"));
				}
				if (!jsonObject.isNull("babyName")) {
					babyPrayLetterInfo.setBabyName(jsonObject
							.getString("babyName"));
				}
				if (!jsonObject.isNull("babyPhoto")) {
					babyPrayLetterInfo.setBabyPhoto(jsonObject
							.getString("babyPhoto"));
				}

				if (!jsonObject.isNull("paryletterList")) {
					JSONArray jsonArray = jsonObject
							.getJSONArray("paryletterList");
					PrayLetterInfo prayLetterInfo;
					List<PrayLetterInfo> prayLetterInfoList = new ArrayList<PrayLetterInfo>();
					for (int i = 0; i < jsonArray.length(); i++) {
						JSONObject tempJsonObject = jsonArray.getJSONObject(i);
						prayLetterInfo = new PrayLetterInfo();
						prayLetterInfo.setUserId(tempJsonObject
								.getString("userId"));
						if (!tempJsonObject.isNull("callName")) {
							prayLetterInfo.setCallName(tempJsonObject
									.getString("callName"));
						}
						if (!tempJsonObject.isNull("nickName")) {
							prayLetterInfo.setNickName(tempJsonObject
									.getString("nickName"));
						}
						if (!tempJsonObject.isNull("content")) {
							prayLetterInfo.setContent(tempJsonObject
									.getString("content"));
						}
						if (!tempJsonObject.isNull("createDate")) {
							prayLetterInfo.setCreateDate(tempJsonObject
									.getString("createDate"));
						}
						if (!tempJsonObject.isNull("audio")) {
							prayLetterInfo.setAudio(tempJsonObject
									.getString("audio"));
						}
						prayLetterInfoList.add(prayLetterInfo);
					}
					babyPrayLetterInfo.setPrayLetterInfo(prayLetterInfoList);
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
	}

	public BabyPrayLetterInfo getBabyPrayLetterInfo() {
		return babyPrayLetterInfo;
	}

	public void setBabyPrayLetterInfo(BabyPrayLetterInfo babyPrayLetterInfo) {
		this.babyPrayLetterInfo = babyPrayLetterInfo;
	}

}
